<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ page import="net.doglog.*" %>
<%@ page import="java.util.*" %>

<%@ include file="/header.jsp" %>
<%
Post post = (Post) request.getAttribute("post");
if (post == null) {
	BlogUtil.printError(out, Blog.errorNoPostFound);
} else {
%>
<div class="post">
	<h3><%= post.getTitle() %></h3>
	<span class="hint"><%= Blog.author %> 发表于 <%= PostUtil.formatTime(post.getTime()) %></span>
	<a class="anchor" href="#comment">评论</a>
	<span><%= PostUtil.formatTags(post.getTags()) %></span>
	<div><%= post.getContent() %></div>
</div>
<div class="comments">
<form action="/post/<%= post.getId() %>" method="post">
<%
String parent = BlogUtil.attribute(request, "parent");
String speaker = BlogUtil.attribute(request, "speaker");
String content = BlogUtil.attribute(request, "content");
String error = BlogUtil.attribute(request, "error");
%>
	<h4><a class="anchor" name="comment">评论</a></h4>
	<input type="hidden" name="parent" id="parent" value="<%= parent %>" />
	<p>
		<label for="speaker">您的名字：</label><br />
		<input type="text" maxlength="40" name="speaker" id="speaker" value="<%= speaker %>" />
	</p>
	<p>
		<label for="content">评论内容：<span id="tospan"></span></label><br />
		<textarea name="content" id="content"><%= content %></textarea>
	</p>
	<p>
		<input type="submit" value="提交评论" />
		<span class="error"><%= error %></span>
	</p>
</form>
<script type="text/javascript">
function reply(keystr, speaker) {
	if (confirm("确定要回复 " + speaker + " 吗？")) {
		var hidden = document.getElementById("parent");
		hidden.value = keystr;
		var tospan = document.getElementById("tospan");
		tospan.innerHTML = "（回复 " + speaker + "）";
	}
}
</script>
<%
	List<Comment> comments = post.getComments();
	if (comments.size() == 0) {
		BlogUtil.printError(out, Blog.errorNoCommentFound);
	} else {
		out.print(BlogUtil.listComments(comments, null));
	}
%>
</div>
<% } // end if (post == null) %>
<%@ include file="/footer.jsp" %>
